﻿using System;

namespace IceDog.SmallProject.EnumFlagsAttribute
{

    class Program
    {
        static void Main(string[] args)
        {
            var loginUser = AdvanceUserAction.LoginUserAction;
            if (UserActionManager.CheckUserHasOwnAction(loginUser, UserAction.PreviewArticle))
            {
                Console.WriteLine("loginUser can preview");
            }
            else
            {
                Console.WriteLine("loginUser can not preview");
            }
            Console.WriteLine("-----------------------------------");
            if (UserActionManager.CheckUserHasOwnAction(loginUser, UserAction.DeleteArticle))
            {
                Console.WriteLine("loginUser can delete");
            }
            else
            {
                Console.WriteLine("loginUser can not delete");
            }
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("remove preview action");
            loginUser = UserActionManager.RemoveUserAction(loginUser, UserAction.PreviewArticle);

            if (UserActionManager.CheckUserHasOwnAction(loginUser, UserAction.PreviewArticle))
            {
                Console.WriteLine("loginUser can preview");
            }
            else
            {
                Console.WriteLine("loginUser can not preview");
            }
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("add delete action");
            loginUser = UserActionManager.AddUserAction(loginUser, UserAction.DeleteArticle);
            if (UserActionManager.CheckUserHasOwnAction(loginUser, UserAction.DeleteArticle))
            {
                Console.WriteLine("loginUser can delete");
            }
            else
            {
                Console.WriteLine("loginUser can not delete");
            }
            Console.WriteLine("-----------------------------------");
            //可以去掉和添加上 UserAction的[Flags]特性，看此处的输出
            //无 [Flags]  登录用户的行为有：120
            //有 [Flags]  登录用户的行为有：DeleteArticle, CommentArticle, LikeArticle, CollectionArticle
            Console.WriteLine("登录用户的行为有："+loginUser.ToString());
            Console.WriteLine("-----------------------------------");
            loginUser = UserActionManager.ReverseUserAction(loginUser, UserAction.DeleteArticle);
            if (UserActionManager.CheckUserHasOwnAction(loginUser, UserAction.DeleteArticle))
            {
                Console.WriteLine("loginUser can delete");
            }
            else
            {
                Console.WriteLine("loginUser can not delete");
            }
            loginUser = UserActionManager.ReverseUserAction(loginUser, UserAction.DeleteArticle);
            if (UserActionManager.CheckUserHasOwnAction(loginUser, UserAction.DeleteArticle))
            {
                Console.WriteLine("loginUser can delete");
            }
            else
            {
                Console.WriteLine("loginUser can not delete");
            }
        }
    }
}
